package com.yuan.yblog.common.pojo;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import com.yuan.yblog.common.consts.RedisKey;
import com.yuan.yblog.common.utils.uuid.IdUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @author hepeiyuan on 2024/5/18 12:52
 * @description
 */
@Data
@Schema(description = "图片验证码")
public class VerificationCodeImg {

    @Schema(description = "验证码标识")
    private String captchaId;

    @Schema(description = "验证码图片Base64")
    private String imageBase64;

    @Schema(description = "图像数据编码方式")
    private String EncodingMode;

    @Schema(description = "有效时间（单位：秒）")
    private Long expire;

    public static VerificationCodeImg createBase64Img(LineCaptcha lineCaptcha) {
        VerificationCodeImg verificationCodeImg = new VerificationCodeImg();
        if (lineCaptcha == null) {
            return verificationCodeImg;
        }
        verificationCodeImg.setCaptchaId(IdUtils.simpleUUID());
        verificationCodeImg.setImageBase64(lineCaptcha.getImageBase64());
        verificationCodeImg.setEncodingMode("base64");
        verificationCodeImg.setExpire(RedisKey.CAPTCHA_EXPIRE);

        return verificationCodeImg;
    }

}
